/**
 * ElementPlus 图标统一配置文件
 * 用于集中管理所有页面使用的图标，避免重复配置和遗漏
 * 
 * 使用方法：
 * 1. 在HTML中引入此文件：<script src="../js/icons.js"></script>
 * 2. 在Vue应用中使用：window.IconsConfig.registerIcons(app)
 */

window.IconsConfig = {
    /**
     * 获取所有可用的图标组件
     */
    getIcons() {
        if (!window.ElementPlusIconsVue) {
            console.error('ElementPlusIconsVue 未加载，请确保已正确引入 Element Plus Icons');
            return {};
        }
        
        return {
            // 文件操作相关图标
            Upload: window.ElementPlusIconsVue.Upload,
            UploadFilled: window.ElementPlusIconsVue.UploadFilled,
            Download: window.ElementPlusIconsVue.Download,
            Document: window.ElementPlusIconsVue.Document,
            Folder: window.ElementPlusIconsVue.Folder,
            Delete: window.ElementPlusIconsVue.Delete,
            
            // 状态相关图标
            Loading: window.ElementPlusIconsVue.Loading,
            Check: window.ElementPlusIconsVue.Check,
            SuccessFilled: window.ElementPlusIconsVue.SuccessFilled,
            Warning: window.ElementPlusIconsVue.Warning,
            WarningFilled: window.ElementPlusIconsVue.WarningFilled,
            CircleClose: window.ElementPlusIconsVue.CircleClose,
            
            // 界面操作相关图标
            Setting: window.ElementPlusIconsVue.Setting,
            ArrowDown: window.ElementPlusIconsVue.ArrowDown,
            ArrowUp: window.ElementPlusIconsVue.ArrowUp,
            ArrowLeft: window.ElementPlusIconsVue.ArrowLeft,
            ArrowRight: window.ElementPlusIconsVue.ArrowRight,
            
            // 数据分析相关图标
            TrendCharts: window.ElementPlusIconsVue.TrendCharts,
            DataAnalysis: window.ElementPlusIconsVue.DataAnalysis,
            PieChart: window.ElementPlusIconsVue.PieChart,
            
            // 其他常用图标
            Plus: window.ElementPlusIconsVue.Plus,
            Minus: window.ElementPlusIconsVue.Minus,
            Close: window.ElementPlusIconsVue.Close,
            Search: window.ElementPlusIconsVue.Search,
            Refresh: window.ElementPlusIconsVue.Refresh,
            View: window.ElementPlusIconsVue.View,
            Hide: window.ElementPlusIconsVue.Hide,
            Edit: window.ElementPlusIconsVue.Edit,
            More: window.ElementPlusIconsVue.More,
            
            // 导航相关图标
            Menu: window.ElementPlusIconsVue.Menu,
            House: window.ElementPlusIconsVue.House,
            Back: window.ElementPlusIconsVue.Back,
            
            // 时间相关图标
            Clock: window.ElementPlusIconsVue.Clock,
            Calendar: window.ElementPlusIconsVue.Calendar,
            
            // 用户相关图标
            User: window.ElementPlusIconsVue.User,
            UserFilled: window.ElementPlusIconsVue.UserFilled,
            
            // 工具相关图标
            Tools: window.ElementPlusIconsVue.Tools,
            Key: window.ElementPlusIconsVue.Key,
            Lock: window.ElementPlusIconsVue.Lock,
            Unlock: window.ElementPlusIconsVue.Unlock
        };
    },

    /**
     * 为Vue应用注册图标组件
     * @param {Object} app - Vue应用实例
     */
    registerIcons(app) {
        const icons = this.getIcons();
        
        // 将图标注册为全局组件
        Object.keys(icons).forEach(iconName => {
            if (icons[iconName]) {
                app.component(iconName, icons[iconName]);
            }
        });
        
        console.log(`已注册 ${Object.keys(icons).length} 个图标组件`);
        return icons;
    },

    /**
     * 获取图标的computed属性配置
     * 用于在Vue组件的computed中使用
     */
    getIconsComputed() {
        const icons = this.getIcons();
        const computed = {};
        
        Object.keys(icons).forEach(iconName => {
            computed[iconName] = () => icons[iconName];
        });
        
        return computed;
    },

    /**
     * 检查图标是否可用
     * @param {string} iconName - 图标名称
     */
    isIconAvailable(iconName) {
        const icons = this.getIcons();
        return icons[iconName] !== undefined;
    },

    /**
     * 获取所有可用图标的名称列表
     */
    getAvailableIconNames() {
        return Object.keys(this.getIcons());
    }
};

// 提供便捷的全局方法
window.registerElementPlusIcons = function(app) {
    return window.IconsConfig.registerIcons(app);
};

// 在控制台输出可用图标列表（开发调试用）
if (typeof console !== 'undefined') {
    console.log('ElementPlus Icons 配置已加载');
    console.log('可用图标:', window.IconsConfig.getAvailableIconNames());
}